using IQIGame.Onigao.Framework;
using System.Collections.Generic;

namespace IQIGame.Onigao.GamePlay
{
    [SerializableGroup(SerializableGroup.LevelModuleConfig)]
    public partial class LevelGamePlayConfig : IModularConfig
    {
        #region 原生配置字段
        /// <summary>
        /// 所有服务
        /// </summary>
        public Dictionary<int, LevelServiceConfig> services;
        /// <summary>
        /// 所有实体
        /// </summary>
        public LevelEntityConfig[] entityConfigs;
        /// <summary>
        /// 局部天气显示对象的Hierarchy路径与业务id的映射，key代表InstanceId
        /// </summary>
        public IReadOnlyDictionary<string, int> weatherObjPathIDs;
        /// <summary>
        /// 局部天气显示对象业务id与天气类型的映射，业务id为0代表全局id
        /// </summary>
        public IReadOnlyDictionary<int, int> weatherTypes;
        #endregion 原生配置字段

        /// <summary>
        /// 优化的映射，Init时动态生成
        /// </summary>
        public BetterList<int, LevelEntityConfig> entityMap { get; private set; }

        /// <summary>
        /// 初始化方法主要是为了创建提高运行效率的（冗余的）缓存数据
        /// 没有直接生成到配置是因为可能存在（序列化支持不便/容易产生冗余，存储效率不高）等情况
        /// </summary>
        public void Init()
        {
            entityMap = new BetterList<int, LevelEntityConfig>();
            for (int i = 0; i < entityConfigs.Length; i++)
            {
                LevelEntityConfig config = entityConfigs[i];
                if (!entityMap.ContainsKey(config.id))
                {
                    entityMap.Add(config.id, config);
                }
            }
        }
    }
}
